
#include <common.h>

word_t expr(char *e, bool *success) ;
void test_expr() {
  FILE *fp = fopen("tools/gen-expr/input", "r");
  if (fp == NULL) perror("test_expr error");

  char *e = NULL;
  word_t correct_res;
  size_t len = 0;
  ssize_t read;
  bool success = false;

  while (true) {
    if(fscanf(fp, "%d ", &correct_res) == -1) break;
    read = getline(&e, &len, fp);
    e[read-1] = '\0';
    
    //printf("%s\n", e); 
    word_t res = expr(e, &success);
    
    //assert(success);
    if (res != correct_res) {
      puts(e);
      printf("expected: %d, got: %d\n", correct_res, res);
      assert(0);
    }
  }

  fclose(fp);
  if (e) free(e);

  Log("expr test pass");
}